package com.prothink.controller.statistics;

import com.prothink.entity.ProductCollection;
import com.prothink.service.ProductCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *商品收藏控制层
 * @Date 2022 11 24
 */
@CrossOrigin
@Controller
@RequestMapping("productCollectionService")
public class ProductCollectionController {
    @Autowired
    private ProductCollectionService productCollectionService;

    /**
     * 获取全部被收藏的商品
     * @param productCollection 商品收藏实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/getproductCollectionService")
    public List getProductCollection(ProductCollection productCollection){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            productCollection.setCollectTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return productCollectionService.getProductCollection(productCollection);
    }

    /**
     * 添加收藏商品信息
     * @param productCollection 商品收藏实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/addproductCollectionService")
    public Integer addProductCollection(ProductCollection productCollection){
        return productCollectionService.addProductCollection(productCollection);
    }
}
